const axios = require('axios')


module.exports = {
    namespaced: true,
    state: {
        pageData: {
            pageSize: 4,
            currentPage: 1,
            total: 0,
            rows: []
        },
        search: {
            searchType: "",
            searchValue: ""
        }
    },
    mutations: {
        /**
        * =============================李兴乾====================
        */
        //改变pageData中的数组和总数
        getGoods(state, data) {
            state.pageData.total = data.total;
            state.pageData.rows = data.rows
            // console.log(state.studentsData);
        },
        //分页操作
        changepageSize(state, size) {
            state.pageData.pageSize = size;
            // console.log(state.pageData.pageSize);

        },
        changePage(state, page) {
            state.pageData.currentPage = page
            // console.log(page);

        },

        /**
        * =============================李兴乾====================
        */
    },
    actions: {
        /**
         * ========================================李兴乾===============================
         */
        //分页获取上架商品
        async getGoodsCellAsync(context, shopsId) {
            // console.log(shopsId)
            const searchData = context.state.search
            let fy = {
                pageSize: context.state.pageData.pageSize,
                currentPage: context.state.pageData.currentPage,
                ...searchData,
                shopsId: shopsId,
                state: "上架"
            }
            const { data } = await axios.get("/goods/getGoodsSell", { params: fy });
            // console.log(data);
            //使用mutations函数
            context.commit('getGoods', data);
        },
        //下架商品 '/goods/deleteGoodsSell'
        async deleteGoodsCellAsync(context, id) {
            const { data } = await axios.get("/goods/deleteGoodsSell", { params: { _id: id } });
            console.log(data);
            // context.dispatch('getGoodsCellAsync')
        },
        //修改上架商品/goods/updateGoodsSell
        async updataGoodsCellAsync(context, row) {
            console.log(row)
            const { data } = await axios.post("/goods/updateGoodsSell", row);
            console.log(data);
            // context.dispatch('getGoodsCellAsync')
        }
        /**
         * ========================================李兴乾===============================
         */
        ,
        

    }



}